package com.example.demo.controller;

import com.example.demo.entity.Role;
import com.example.demo.mapper.RoleMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

@Api(tags="character")
@RestController
@EnableSwagger2
public class RoleController {
    @Autowired
    private RoleMapper roleMapper;

    @ApiOperation(value = "添加角色")
    @GetMapping("/addcharacter")
    public int AddUser(Role role){
        return roleMapper.insert(role);
    }
    @ApiOperation(value = "角色查询")
    @GetMapping("/getcharacter")
    public List<Role> getAll(){
        return roleMapper.search();
    }
    @ApiOperation(value = "模糊查询")
    @GetMapping("/getcharacterbyname")
    public List<Role> getSearch(String cname){
        return roleMapper.searchByName(cname);
    }
    @ApiOperation(value = "删除角色")
    @GetMapping("/deletecharacter")
    public int delete(int id){
        return roleMapper.delete(id);
    }
    @ApiOperation(value = "更新角色信息")
    @GetMapping("/updatecharacter")
    public int update(Role role){
        return roleMapper.update(role);
    }
}
